<?php

    class Logger
    {
        /**
         * Writes message to log. 
         *
         * @param string $logFile path to log file
         * @param string $msg 
         */
        public static function Log($logFile, $msg)
        {
            $f = @fopen($logFile, "a");
            if (!$f)
            {
                return;
            }
            
            fprintf($f, "[%s] %s\n", date("Y-m-d H:i:s"), $msg);
            fclose($f);
        }
        
        /**
         * Writes exception details to log.
         * 
         * @param Exception $e
         */
        public static function LogException($logFile, Exception $e)
        {
            self::log($logFile, self::GetExceptionDetails($e));
        }
        
        /**
         * Returns exception details for logging.
         *
         * @param Exception $e
         * @return string
         */
        public static function GetExceptionDetails(Exception $e)
        {
            return "Exception details:\n\tmessage: '" . $e->getMessage() . 
                    "'\n\tcode: " . $e->getCode() . 
                    "\n\tline: " . $e->getLine() . 
                    "\n\ttrace: \"" . $e->getTraceAsString() . "\"";            
        }
    }

?>